import 'package:flutter/material.dart';
import 'package:flutter_default_project/models.dart';
import 'package:flutter_default_project/state_container.dart';

class DetailScreen extends StatelessWidget {
  final Todo todo;
  const DetailScreen({required this.todo, super.key});

  @override
  Widget build(BuildContext context) {
    final container = StateContainer.of(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('detail'),
        actions: [
          IconButton(
            onPressed: () {
              container.removeTodo(todo);
              Navigator.pop(context, todo);
            },
            icon: Icon(Icons.delete),
          ),
        ],
      ),
      body: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Checkbox(
            value: todo.complete,
            onChanged: (value) {
              StateContainer.of(context).updateTodo(todo, isCompleted: value);
            },
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(todo.task, style: TextStyle(fontSize: 24)),
              Text(todo.note),
            ],
          ),
        ],
      ),
    );
  }
}
